<!-- 评审审批 -->
<template>
    <div class="edu-page-warp">
      <el-card shadow="never">
        <el-row type="flex" justify="space-between" class="con_title">
          <el-col :span="6">
            <h2 class="edu-page-title">{{auditType==='audit'?this.$t('common.btn.approve'):this.$t('message.Look')}}</h2>
          </el-col>
          <el-col :span="3" style="text-align: right;">
            <el-button @click="back">{{this.$t('common.btn.back')}}</el-button>
          </el-col>
        </el-row>
        <h2 class="edu-page-title">{{$t('common.text.baseInfo')}}</h2>
        <baseData ref="baseDataRef" :label="label" :data="data" :eidtState="auditType!=='audit'" :row="row" :auditFlag="auditFlag"
        :resultState="resultState" @emit:complete="complete" :editForm="auditType==='audit'&&editForm"></baseData>
      </el-card>
    <el-card shadow="never">
      <auditProgress :data="auditList" ></auditProgress>
    </el-card>
    </div>
</template>

<script>
import { tutorAuditDetail, tutorCheck } from "common/src/api/paperBlindTrial";
import baseData from '../common/baseData';
import auditProgress from '../common/auditProgress';
import commonMixins from 'common/src/views/practiceManagement/commonMixins';
import { approvalThrough, approvalReject, approvelDetail } from "common/src/api/approval";
export default {
    components: {
        baseData,
        auditProgress
    },
    mixins: [commonMixins],
    props: {
      row: {
        type: Object,
        default: {}
      },
      auditType: {
        type: String
      },
      resultState: {
        type: Boolean,
        default: false
      },
      editForm: {
        type: Boolean,
      }
    },
    data() {
        return {
          data: {},
          label: [
              { label: this.$t('label.schoolTerm'), prop: 'yearTermI18n' },
              { label: this.$t('label.stuCode'), prop: 'stuNo' },
              { label: this.$t('label.stuName'), prop: 'stuName' },
              { label: this.$t('label.grade'), prop: 'grade' },
              { label: this.$t('label.trainingLevel'), prop: 'eduLevelI18n' },
              { label: this.$t('label.trainingCategory'), prop: 'eduModeI18n' },
              { label: this.$t('label.degreeCategory'), prop: 'degreeTypeI18n' },
              { label: this.$t('label.formLearning'), prop: 'studyFormI18n' },
              { label: this.$t('paperBlindTrial.batchName'), prop: 'batchNo' },
              { label: this.$t('label.college'), prop: 'academyName' },
              { label: this.$t('paperBlindTrial.stuMajor'), prop: 'majorName' },
              { label: this.$t('paperBlindTrial.firstDisciplineName'), prop: 'firstDisciplineName' },
              { label: this.$t('paperBlindTrial.secondaryDisciplineName'), prop: 'secondaryDisciplineName' },
              { label: this.$t('paperBlindTrial.preDefenseFlag'), prop: 'preDefenseFlag' },
              { label: this.$t('achievementApply.thesisTitle'), prop: 'thesisTitle' },
              { label: this.$t('paperBlindTrial.paperEnName'), prop: 'thesisTitleEn' },
              { label: this.$t('paperBlindTrial.paperKeyword'), prop: 'thesisKeyword' },
              { label: this.$t('paperBlindTrial.paperLang'), prop: 'thesisLang' },
              { label: this.$t('paperBlindTrial.paperDirection'), prop: 'thesisResearchField', col: '24' },
              { label: this.$t('paperBlindTrial.paperItemLabel'), prop: 'BLIND_REVIEW_PAPER', type: 'file' },
              { label: this.$t('paperBlindTrial.summaryItemLabel'), prop: 'BLIND_SUMMARY', type: 'file' },
              { label: this.$t('paperBlindTrial.profileItemLabel'), prop: 'BLIND_PROFILE', type: 'file' },
              { label: this.$t('paperBlindTrial.selfFormItemLabel'), prop: 'BLIND_SELF_EVALUATION', type: 'file' },
              { label: this.$t('paperBlindTrial.otherItemLabel'), prop: 'BLIND_OTHER', type: 'file' },
          ],
          applyDetail: {},
          auditList: [],
          workFlowId: '',
          options: {
            thesisLang: [],
            preDefenseFlag: [
              { label: this.$t('common.text.yes'), value: 'Y', type: 'success' },
              { label: this.$t('common.text.no'), value: 'N', type: 'warning' }
            ]
          },
          auditFlag: {}
        };
    },
    computed: {

    },
    created() {
      },
    mounted() {
      let param = {
        WRITE_PAPER_LANGUAGE: 'thesisLang', // 语种
      };
      this.initOptions(param);
      this.getDetail();
    },
    methods: {
      back() {
        this.$emit('emit:back');
      },
      complete() {
        let audits = this.$refs.baseDataRef.audits;
        if (audits.staus === 'unpass') {
          if (this.editForm) {
            this.$confirm(this.$t('achievementApply.refuseInfo'), this.$t('achievementApply.tipsTitle'), {
              confirmButtonText: this.$t('message.confirm'),
              cancelButtonText: this.$t('message.cancel'),
              type: 'warning'
            }).then(() => {
              this.tutorAuditFunc(audits);
            });
            return;
          }
          this.ApplyReject(audits);
        } else if (audits.staus === 'pass') {
          if (this.editForm) {
            this.$eduConfirm(this.$t('teachers.comfirmApprove'), this.$t('common.btn.approve')).then(() => {
              this.tutorAuditFunc(audits);
            });
            return;
          }
          this.ApplyPass(audits)
        }
      },
      // 导师审批
      tutorAuditFunc (audits) {
        let param = {
          processStatus: audits.staus === 'unpass' ? '0' : '1',
          content: audits.staus === 'unpass' ? (audits.msg || '不同意请修改论文') : (audits.msg || '同意'),
          applyIds: [this.row.applyId]
        };
        tutorCheck(param).then(res=>{
          if (res.code == 200) {
            this.$message({
              type: "success",
              message: this.$t('shortTermApprove.examinePass')
            });
            this.back();
          }
        });
      },
      // 审批通过
      ApplyPass(audits) {
        this.$eduConfirm(this.$t('teachers.comfirmApprove'), this.$t('common.btn.approve')).then(() => {
          let param = {
            no: this.workFlowId,
            content: audits.msg || '同意',
            approveAttachment: [],
            oaNo: this.workFlowId,
            remark: null,
            callbackEachTime: true
          };
          approvalThrough(param).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: this.$t('shortTermApprove.examinePass')
              });
              this.back();
            }
          });
        });
      },
      // 审批驳回
      ApplyReject(audits) {
        this.$confirm(this.$t('achievementApply.refuseInfo'), this.$t('achievementApply.tipsTitle'), {
          confirmButtonText: this.$t('message.confirm'),
          cancelButtonText: this.$t('message.cancel'),
          type: 'warning'
        }).then(() => {
          let param = {
            content: audits.msg || '不同意请修改论文',
            no: this.workFlowId,
            approveAttachment: [],
            oaNo: this.workFlowId,
            remark: null,
            callbackEachTime: true
          };
          approvalReject(param).then(res => {
            if (res.code == 200) {
              this.$message({
                type: "success",
                message: this.$t('shortTermApprove.examinePass')
              });
              this.back();
            }
          });
        });
      },
      // 获取审批记录
      getApprovelDetail (workFlowId, type = 'one') {
        let param = {
          no: workFlowId
        };
        if (!param.no || param.no === '') {
            return;
        }
        approvelDetail(param).then(res => {
          if (res && res.data) {
            let historyList = _.cloneDeep(res.data.listApproveHistory);
            if (type === 'second') {
              historyList[0].content = '发起盲审专员审批流程';
              this.auditList = this.auditList.concat(historyList);
              return;
            }
            this.auditList = historyList;
            if (this.data.workflowBlindNo) {
              this.getApprovelDetail(this.data.workflowBlindNo, 'second');
            }
          }
        });
      },
      // 获取详情
      getDetail () {
        tutorAuditDetail(this.row.applyId).then(res=>{
          if (res.code === 200) {
            this.workFlowId = this.editForm ? res.data.workflowNo : res.data.workflowBlindNo;
            this.data = res.data;
            this.data.preDefenseFlag = this.fieldChange(this.options.preDefenseFlag, this.data.preDefenseFlag);
            this.data.thesisLang = this.fieldChange(this.options.thesisLang, this.data.thesisLang);
            if (this.auditType!=='audit') {
              this.$refs.baseDataRef.auditForm = {
                confirmResField: res.data.confirmResField,
                confirmStyleContent: res.data.confirmStyleContent,
                confirmStyle: res.data.confirmStyle,
              };
            }
            this.getApprovelDetail(res.data.workflowNo);
          }
        });
      }
    }
};
</script>

<style scoped lang="scss">
.con {
    background-color: white;
    padding: 20px;
    &_title {
        width: 100%;
        border-bottom: solid #ccc 2px;
        padding-bottom: 20px;
    }
    &_footer {
        display: flex;
        flex-direction: row-reverse;
        border-top: solid #ccc 1px;
        padding-top: 10px;
    }
}
</style>
